FROM ubuntu:20.04 as base

ENV TZ=Asia/Shanghai \
    DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update && apt --fix-broken -y install
RUN apt-get install -y wget git
RUN apt-get install -y fonts-liberation libasound2  libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2
RUN apt-get install -y libcurl3-gnutls  libcurl3-nss  libcurl4 \
                       libdbus-1-3 libdrm2 libexpat1 libgbm1 libglib2.0-0 \
                       libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libu2f-udev libvulkan1
RUN apt-get install -y libx11-6 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 xdg-utils

FROM base as builder

RUN wget --no-check-certificate https://dl.google.com/go/go1.19.12.linux-amd64.tar.gz
RUN tar -xf go1.19.12.linux-amd64.tar.gz && mv go /usr/local/
ENV GOROOT=/usr/local/go \
    GOPROXY=https://goproxy.cn \
    GOPRIVATE=atomgit.com \
    PATH=$PATH:/usr/local/go/bin
RUN echo $(go version)

ADD . /data/icep-service
WORKDIR /data/icep-service

RUN go mod tidy
RUN CGO_ENABLE=0 go build -o icep-service


FROM base

RUN wget --no-check-certificate https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN dpkg -i ./google-chrome-stable_current_amd64.deb

COPY --from=builder /data/icep-service/icep-service /etc/icep-service/icep-service
COPY --from=builder /data/icep-service/config /etc/icep-service/config
ADD ./deploy/template /etc/icep-service/template

RUN cp -r -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
COPY ./deploy/fonts.tar.gz /opt/fonts.tar.gz
RUN tar -xf /opt/fonts.tar.gz -C /usr/share/fonts/truetype/liberation/

WORKDIR /etc/icep-service/

ENV ICEP_SERVER_PORT=9082

CMD ["./icep-service"]
